Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
dbgate-query-splitter
Advanced tools
Splits long SQL query into into particular statements. Designed to have zero dependencies and to be fast. Also supports nodejs-streams.
Supports following SQL dialects:
import {
splitQuery,
mysqlSplitterOptions,
mssqlSplitterOptions,
postgreSplitterOptions,
} from "dbgate-query-splitter";
const output = splitQuery(
"SELECT * FROM `table1`;SELECT * FROM `table2`;",
mysqlSplitterOptions
);
// output is ['SELECT * FROM `table1`', 'SELECT * FROM `table2`']
Function splitQueryStream accepts input stream and query options. Result is object stream, each object for one splitted query. From version 4.9.0, piping byline stream is not required.
const {
mysqlSplitterOptions,
mssqlSplitterOptions,
postgreSplitterOptions,
} = require("dbgate-query-splitter");
const {
splitQueryStream,
} = require("dbgate-query-splitter/lib/splitQueryStream");
const fs = require("fs");
const fileStream = fs.createReadStream("INPUT_FILE_NAME", "utf-8");
const splittedStream = splitQueryStream(fileStream, mysqlSplitterOptions);
By default, string array is returned. However, if you need to return row/column number information for splitted commands, use returnRichInfo option:
import { splitQuery, mysqlSplitterOptions } from "dbgate-query-splitter";
const output = splitQuery("SELECT * FROM `table1`;SELECT * FROM `table2`;", {
...mysqlSplitterOptions,
returnRichInfo: true,
});
Output is:
[
{
text: 'SELECT * FROM `table1`',
start: { position: 0, line: 0, column: 0 },
end: { position: 22, line: 0, column: 22 },
trimStart: { position: 0, line: 0, column: 0 },
trimEnd: { position: 22, line: 0, column: 22 }
},
{
text: 'SELECT * FROM `table2`',
start: { position: 23, line: 0, column: 23 },
end: { position: 46, line: 1, column: 22 },
trimStart: { position: 24, line: 1, column: 0 },
trimEnd: { position: 46, line: 1, column: 22 }
}
]
Please run tests before pushing any changes.
yarn test
FAQs
SQL Query splitter for verious database engines
The npm package dbgate-query-splitter receives a total of 1,549 weekly downloads. As such, dbgate-query-splitter popularity was classified as popular.
We found that dbgate-query-splitter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.